package jbrowser.gui.settings;

import java.util.Properties;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

/**
 * DefaultTableModel model = (DefaultTableModel) tblProperties.getModel(); for
 * (Object key : properties.keySet()) { model.addRow(new Object[]{key, (Object)
 * Boolean.valueOf(properties.getProperty(key.toString()))}); }
 *
 * @author buczko
 */
class DefaultPropertyEditor extends JScrollPane {

    JTable tblProperties;
    Properties properties;

    public Properties getProperties() {
        return properties;
    }

    public void setProperties(Properties properties) {
        this.properties = properties;
        DefaultTableModel model = new DefaultTableModel(
                new Object[][]{},
                new String[]{
            properties.getProperty("config.editor.key.name", "Property name"),
            properties.getProperty("config.editor.value.name", "Value")
        }) {
            Class[] types = new Class[]{
                java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean[]{
                false, true
            };

            @Override
            public Class getColumnClass(int columnIndex) {
                return types[columnIndex];
            }

            @Override
            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit[columnIndex];
            }
        };
        for (Object key : properties.keySet()) {
            model.addRow(new Object[]{key, properties.get(key)});
        }
        tblProperties.setModel(model);
    }

    public DefaultPropertyEditor(Properties properties) {
        tblProperties = new JTable();
        setProperties(properties);
        setViewportView(tblProperties);
    }
}
